package com.doraemon.staging.mvc.springmvc.editor;


import com.doraemon.staging.util.ObjectUtil;
import com.doraemon.staging.util.StringUtil;
import com.doraemon.staging.util.ValueUtil;
import org.springframework.web.util.HtmlUtils;

import java.beans.PropertyEditorSupport;


/**
 * double 属性转换器.
 *
 * @author yangz
 * @date 2013-3-30 下午3:14:08
 */

public class DoubleEditor extends PropertyEditorSupport {

    public void setAsText(String text) throws IllegalArgumentException {
        if (!ObjectUtil.isEmpty(text)) {
            setValue(Double.valueOf(HtmlUtils.htmlEscape(StringUtil.trim(text))));
        } else {
            setValue(null);
        }
    }

    public String getAsText() {
        Object value = getValue();
        return value == null ? null : ValueUtil.getString(value);
    }
}